package com.supermarket.controller;

import com.supermarket.entity.OperationLog;
import com.supermarket.service.OperationLogService;
import com.supermarket.utils.Result;
import com.supermarket.vo.OperationLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/operationLog")
@Api(tags = "操作日志相关接口")
@Slf4j
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    @GetMapping("/list")
    @ApiOperation("查询所有操作日志")
    public Result<List<OperationLogVo>> list() {
        List<OperationLogVo> list = operationLogService.getAllLogs();
        return Result.success(list);
    }

    @GetMapping("/user/{userId}")
    @ApiOperation("根据用户ID查询操作日志")
    public Result<List<OperationLogVo>> getByUserId(@PathVariable Long userId) {
        List<OperationLogVo> list = operationLogService.getLogsByUserId(userId);
        return Result.success(list);
    }
}